package hpp.problems;

/**
 * 题目：输入一个字符串，打印出该字符串中字符的所有排列
 * Created by hpp on 2017/7/30.
 */
public class Problem28 {


    public static void main(String[] args) {
//        String aa = "abc234dsf";
//        System.out.println(aa.toCharArray().length);
        Problem28 testPermutation=new Problem28();
        testPermutation.permutation("abcd");
    }

    public void permutation(String str){
        int count=0;
        if(str==null)
            return;
        char[] chs=str.toCharArray();
        int point=0;
        System.out.print(chs);
        System.out.print(" ");
        count++;
        char temp1=chs[point];
        chs[point]=chs[++point];
        chs[point]=temp1;
        while(!String.valueOf(chs).equals(str)){
            System.out.print(chs);
            System.out.print(" ");
            count++;
            if(point==str.length()-1){
                temp1 = chs[point];
                chs[point] = chs[0];
                chs[0] = temp1;
                point = 0;
            }else {
                temp1 = chs[point];
                chs[point] = chs[++point];
                chs[point] = temp1;
            }
        }
        System.out.println(count);
    }

    public void permutation2(String str){
        char[] arr = str.toCharArray();
        int length = arr.length-1;
        for(int i=0;i<length;i++){

        }
    }


}
